package com.hunteron.jdbc.dao;

import java.util.ArrayList;
import java.util.List;

import com.hunteron.util.DateFormatUtil;

public class AbstractDao<T> {
	private long total = -1;
	private int perTime = 0;
	private int first = 0;
	private String updateTime = "";

	public AbstractDao() {
		init(5000);
	}
	public AbstractDao(int pertime) {
		init(pertime);
	}
	
	public void initDao() {
		init(perTime);
	}
	
	private void init(int pertime) {
		total = countAll();
		first = 0;
		this.perTime = pertime > 0 ? pertime : 5000;
	}
	
	public boolean hasNext() {
		return first < total;
	}
	
	public List<T> more() {
		List<T> result = getList(first, perTime);
		first += perTime;
		return result;
	}

	public long maxTime(long minTime) {
		return System.currentTimeMillis();
	}
	
	public long countAll() {
		return 0;
	}
	
	public List<T> getList(int first, int max) {
		return new ArrayList<T>(0);
	}
	
	public int insert(List<T> list) {
		return 0;
	}
	public String getUpdateTime() {
		return updateTime;
	}
	public void setUpdateTime(String updateTime) {
		this.updateTime = updateTime;
	}
	public void setUpdateTime(long updateTime) {
		this.updateTime = DateFormatUtil.formatLong(updateTime);
	}
}
